<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Master extends CI_Controller {

	public function __construct()
	{
		parent::__construct();

		$this->load->database();
		$this->load->helper('url');

		$this->load->library('grocery_CRUD');
	}

	public function _example_output($output = null)
	{
		$this->load->view('master/grid',$output);
	}
	public function index()
	{
		$this->_example_output((object)array('output' => '' , 'js_files' => array() , 'css_files' => array()));
	}

	public function cabang()
	{
		$this->load->vars('title','Kode Cabang');

		$crud = new grocery_CRUD();
		
		$crud->set_theme('flexigrid');
		$this->config->load('grocery_crud');
		$crud->set_table('cabang');
		$crud->set_subject('Kode Cabang');
		$crud->unset_texteditor('alamat');
		$crud->unset_export();
		$crud->unset_print();
		
		//$output->title = ;
		$output = $crud->render();

		$this->_example_output($output);
	}
	public function matauang()
	{
		$this->load->vars('title','Kode Mata Uang');

		$crud = new grocery_CRUD();
		
		$crud->set_theme('flexigrid');		
		$this->config->load('grocery_crud');
		$crud->set_table('mata_uang');
		$crud->set_subject('Mata Uang');
		$crud->field_type('uraian','text');
		$crud->unset_export();
		$crud->unset_print();
		$crud->unset_texteditor('uraian');
		$output = $crud->render();

		$this->_example_output($output);
	}
	public function satuan()
	{
		$this->load->vars('title','Kode Satuan');

		$crud = new grocery_CRUD();
		$crud->unset_texteditor('uraian');
		$crud->set_theme('flexigrid');
		$this->config->load('grocery_crud');
		$crud->set_table('satuan');
		$crud->set_subject('Kode Satuan');
		$crud->field_type('uraian','text');
		$crud->unset_export();
		$crud->unset_print();
		
		$output = $crud->render();

		$this->_example_output($output);
	}
	public function hs()
	{
		$this->load->vars('title','HS');

		$crud = new grocery_CRUD();
		$crud->unset_texteditor('uraian');
		$crud->set_theme('flexigrid');
		$this->config->load('grocery_crud');
		$crud->set_table('hs');
		$crud->set_subject('HS');
		$crud->field_type('rekomendasi','dropdown',array('0'=>'Tidak','1'=>'Ya'));
		$crud->field_type('Deskripsi_Barang','text');
		$crud->unset_texteditor('Deskripsi_Barang');
		$crud->unset_export();
		$crud->unset_print();
		
		$output = $crud->render();

		$this->_example_output($output);
	
	}

	public function pelabuhan()
	{
		$this->load->vars('title','Kode Pelabuhan');

		$crud = new grocery_CRUD();
		$crud->unset_texteditor('uraian');
		$crud->set_theme('flexigrid');

		$crud->set_language("indonesian");
		
		$this->config->load('grocery_crud');
		$crud->set_table('pelabuhan');
		$crud->field_type('uraian','text');
		//$crud->display_as('salesRepEmployeeNumber','from Employeer');
		$crud->set_subject('Kode Pelabuhan');
		
		$crud->unset_export();
		$crud->unset_print();
		
		$output = $crud->render();

		$this->_example_output($output);
	}
	public function negara()
	{
		$this->load->vars('title','Kode Negara');

		$crud = new grocery_CRUD();
		$crud->unset_texteditor('uraian');
		$crud->set_theme('flexigrid');

		$crud->set_language("indonesian");
		
		$this->config->load('grocery_crud');
		$crud->field_type('uraian','text');
		$crud->set_table('negara');
		$crud->columns('kode','uraian');
		//$crud->display_as('salesRepEmployeeNumber','from Employeer');
		$crud->set_subject('Kode Negara');
		
		$crud->unset_export();
		$crud->unset_print();
		
		$output = $crud->render();

		$this->_example_output($output);
	}
	public function importir()
	{
		$this->load->vars('title','Importir');

		$crud = new grocery_CRUD();
		
		$crud->set_theme('flexigrid');

		$crud->set_language("indonesian");
		
		$this->config->load('grocery_crud');
		$this->config->set_item('grocery_crud_dialog_forms',true);
		$this->config->set_item('grocery_crud_default_per_page',10);
		
		$crud->set_table('importir');
		//$crud->columns('kode','uraian');
		$crud->field_type('alamat','text');
		$crud->set_subject('Importir');
		$crud->unset_texteditor('alamat');
		$crud->unset_export();
		$crud->unset_print();
		
		$output = $crud->render();

		$this->_example_output($output);
	}

	public function importir_ac()
	{
		$term = $this->input->post('term', TRUE);
		if(!empty($term)){
				
			$rows = $this->db->like('nama',$term)->get('importir')->result_object();
			$keywords = array();
			foreach($rows as $row){
			   $row->tgl_api = date('d/m/Y',strtotime($row->tgl_api .' 00:00:00'));	
			   $keywords[] = array('label' => $row->nama,'data'=>$row, 'value' => $row->nama);
			}        
			//return $keywords;
			unset($rows);
			echo json_encode($keywords);
		}
	}
}

